/**
 * @author Miguel Diaz//257835
 */
package dao;

import com.mongodb.BasicDBObject;
import com.mongodb.DBCollection;
import com.mongodb.DBCursor;
import entity.ChangeLog;
/**
 * this class handle de CR operations in mongo db
 * for the log of changes in commertial establishments
 */
public class ChangeLogMongoCtrl {
    private DBCollection dbcollection = null;

    public ChangeLogMongoCtrl(DBCollection dbcollection) {
        this.dbcollection = dbcollection;
    }

    public DBCollection getDBCollection() {
        return dbcollection;
    }

    public void create(ChangeLog changelog) {

        DBCollection dbc = getDBCollection();
        BasicDBObject document = new BasicDBObject();
        document.put("date", changelog.getDate());
        document.put("administrator", changelog.getAdministrator());
        document.put("commEstablishment", changelog.getComEstablishment());
        document.put("changeType", changelog.getChangeType());
        document.put("initialStatus", changelog.getInitialStatus());
        document.put("finalStatus", changelog.getFinalStatus());
        //validations of unique fields must be inserted here!
        dbc.insert(document);
    }

    

    public void findAdministratorEntities() {
        DBCollection dbc = getDBCollection();
        DBCursor cursor = dbc.find();

        // loop over the cursor and display the retrieved result
        while (cursor.hasNext()) {
            System.out.println(cursor.next());
        }


    }
    
}
